home *** CD-ROM | disk | FTP | other *** search
- Path: solon.com!not-for-mail
- From: GHouck <hksys@teleport.com>
- Newsgroups: comp.lang.c.moderated,comp.lang.c
- Subject: Re: fflush(stdin) - not guaranteed to work?
- Date: 15 Apr 1996 13:12:10 -0500
- Organization: systems hk
- Sender: clc@solutions.solon.com
- Approved: clc@solutions.solon.com
- Message-ID: <4ku3hq$52g@solutions.solon.com>
- References: <4ksjpn$rjt@solutions.solon.com>
- NNTP-Posting-Host: solutions.solon.com
- X-Mailer: Mozilla 1.22 (Windows; I; 32bit)
-
- gohel@csee.usf.edu (Himanshu Gohel) wrote:
- [snip]
- >
- >What is the best way to get rid of the '\n' from the input buffer after
- >a scanf() statement? In the same book on page 263 I've seen the following
- >format used in an fscanf() format specifier:
- >
-
- Himanshu,
- I would recommend the following:
-
- char *pnl;
- char inpBuf[MAXBUF];
- FILE *strm;
- ...
- ...
- while( fgets(inpBuf,sizeof(inpBuf),strm) ) {
- ...
- if( (pnl=strchr(inpBuf,'\n')) ) /* truncate the newline */
- *pnl = '\000';
- ...
- sscanf( inpBuf,... );
- ...
- }
-
- Yours, Geoff Houck
-